package com.morgan.recyclerviewdemo.activity

import android.graphics.Color
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.morgan.recyclerviewdemo.R
import com.morgan.recyclerviewdemo.adapter.TimeLineAdapter
import com.morgan.recyclerviewdemo.entity.TimeLineData
import com.morgan.recyclerviewdemo.itemdecoration.TimeLineItemDecoration
import kotlinx.android.synthetic.main.activity_time_line.*

/**
 *description：
 *<br>author：caowugao
 *<br>time：2020/8/24 0024 10:46
 */
class TimeLineAct : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_time_line)

        recyclerview.layoutManager = LinearLayoutManager(applicationContext, LinearLayoutManager.VERTICAL, false)

        val datas = ArrayList<TimeLineData>()
        val rang = 0..10
        for (i in rang) {
            if (i == 0) {
                datas.add(TimeLineData("已经坚持打卡第${i}天", "time$i", "date$i",ContextCompat.getDrawable(applicationContext, R.drawable.thume_green)!!))
            } else {
                datas.add(TimeLineData("已经坚持打卡第${i}天", "time$i", "date$i",ContextCompat.getDrawable(applicationContext, R.drawable.thume)!!))
            }
        }
        val decoration = TimeLineItemDecoration(applicationContext, datas)
//        decoration.mTimeTextDirection = TimeLineItemDecoration.DIRECTION_TOP
        decoration.mTimeTextDirection = TimeLineItemDecoration.DIRECTION_ALIGN_ITEM
//        decoration.mTimeTextDirection = TimeLineItemDecoration.DIRECTION_BOTTOM
        decoration.mLineColor = Color.RED
//        decoration.setCircleDrawable(ContextCompat.getDrawable(applicationContext, R.drawable.thume)!!)
        recyclerview.addItemDecoration(decoration)
        val adapter = TimeLineAdapter().also {
            it.addData(datas)
        }
        recyclerview.adapter = adapter
    }
}